package entity;
import gui.Camera;
import gui.GameWindow;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import tools.Bimg;
import tools.Input;
import tools.Input.action;
import world.LevelManager;
import world.Platform;


public class Player extends JLabel
{
	private ImageIcon icon;
	public Player(GameWindow win)
	{
		//TODO: Handle image icon path
		icon = new ImageIcon(ClassLoader.getSystemResource("images/player.png"));
		setIcon(icon);
		setBounds(win.getWidth() / 2, win.getHeight() / 2, icon.getIconWidth(), icon.getIconHeight());
	}
	
	public void render(Camera cam)
	{
		//get "real" position of player (bg-position)
		int bgPosX = cam.getX() + getX();
		int bgPosY = cam.getY() + getY();
		
		Rectangle bgBounds = new Rectangle(bgPosX, bgPosY, getWidth(), getHeight());
		if(LevelManager.getInstance().getCurrentLevel().collidesWith(bgBounds)) {
			cam.stop(Input.getLastAction() == action.LEFT || Input.getLastAction() == action.RIGHT);
		}
	}
}